/**
 * Package:com.afteryuan.server.hanlder.core;
 * $Id$
 * Copyright(c) 2001-2005 www.afteryuan.com
 */
package com.afteryuan.server.handler.core;

import com.afteryuan.server.handler.Handler;
import com.afteryuan.server.command.up.CommandUp;
import com.afteryuan.server.command.up.core.QuitRoomUp;
import com.afteryuan.server.command.down.core.PolicyDown;
import com.afteryuan.server.command.down.core.QuitRoomDown;
import com.afteryuan.server.command.down.core.LogoutDown;
import com.afteryuan.server.ConnectSession;
import com.afteryuan.server.config.Configuration;
import com.afteryuan.server.service.SpriteService;
import com.afteryuan.server.data.SpritePool;
import com.afteryuan.server.data.Room;

/**
 * QuitRoomHandler 处理退出Room的请求
 * <p/>
 * 处理步骤:
 * 1.从在线列表中删除此Sprite;
 * 2.通知客户端
 * 3.关闭连接
 * <p><a href="PingHandler.java.html"><i>View Source</i></a></p>
 *
 * @author <a href="mailto:afteryuan@afteryuan.com">$Author$</a>
 * @version $Revision$
 */
public class LogoutHandler implements Handler {
    private SpritePool spritePool;

    public void setSpritePool(SpritePool spritePool) {
        this.spritePool = spritePool;
    }

    public void process(ConnectSession session, CommandUp command) {
        QuitRoomUp cmd = (QuitRoomUp) command;
        spritePool.removeFromServer(cmd.sender);
        session.write(new LogoutDown(cmd.sender));
        session.close();
    }
}